//导入获取设置接口
import {listMallParameter,getMallBillParameterDecimals} from '@/api/global.js'

//存储变量
const state = () => ({
	priceDecimal:0,//单价小数
	numberDecimal:0,//数量小数
	moneyDecimal:0,//金额小数
	serviceTelInfo:{ //客服电话喝开启客服状态
		phone:'',
		parameter:''
	},
	startOrderMoney:``,//起订金额
	noneImge:'',//有图无图模式
	commonityAbbreviation:'',//商品简称
	commonityNorms:'',//商品规格
	commonityQualityGuaranteePeriod:'',//商品有效期
	commonityModel:'',//商品型号
	commonityPlaceOfOrigin:'',//商品产地
	commonityBrand:'',//商品品牌
	commonityZdy:'',//商品自定义
	commonClassity:'',//商品分类 1.按商品分类 2.按品牌分类
	fencang:'',//开启分仓模式 1.开启
	payDate:'',//订单有效i支付时长
	returnOrderName:'',//退货联系人
	returnOrderPhone:'',//退货电话
	returnOrderShengshiqu:'',//退货省市区
	returnOrderAddress:'',//退货地址
	payStatus:'',//在线支付
	cuxiaoOrderPay:'',//促销订单仅支持在线支付
	//在线收款设置
	weixinPay:'',//微信在线收款设置
	tonglianPay:'',//通联在线收款设置
	fuyouPay:'',//富友在线收款设置
	//线下收款设置
	xianxiaPay:'',// 线下收款设置
	visitMode:``,//游客模式
	
})

//赋值
const mutations = {
	//匹配对象赋值 小数位数
	GLOBALDECIMAL(state,val){
		//单价小数
		state.priceDecimal = val && val.filter(v => v.key == 'sys_4_1_2') && val.filter(v => v
				.key == 'sys_4_1_2').length ? val.filter(v => v.key == 'sys_4_1_2')[0].parameter : '';
		//数量小数
		state.numberDecimal = val && val.filter(v => v.key == 'sys_4_1_1') && val.filter(v => v
				.key == 'sys_4_1_1').length ? val.filter(v => v.key == 'sys_4_1_1')[0].parameter : '';
		//金额小数
		state.moneyDecimal = val && val.filter(v => v.key == 'sys_4_1_3') && val.filter(v => v
				.key == 'sys_4_1_3').length ? val.filter(v => v.key == 'sys_4_1_3')[0].parameter : '';
	},
	//匹配对象赋值
	GLOBALSYSTEMSETTING(state, val) {
		state.visitMode = val && val.filter(v => v.key == 'mall_parameter_13') && val.filter(v => v
				.key == 'mall_parameter_13').length ? val.filter(v => v.key == 'mall_parameter_13')[0].parameter : '';
		state.startOrderMoney = val && val.filter(v => v.key == 'mall_parameter_1') && val.filter(v => v
				.key == 'mall_parameter_1').length ? val.filter(v => v.key == 'mall_parameter_1')[0].parameter : '';
		//开启客服状态 mall_parameter_21
		state.serviceTelInfo.parameter = val && val.filter(v => v.key == 'mall_parameter_21') && val.filter(v => v
				.key == 'mall_parameter_21').length ? val.filter(v => v.key == 'mall_parameter_21')[0].parameter : '';
		//开启客服状态 mall_parameter_22
		state.serviceTelInfo.phone = val && val.filter(v => v.key == 'mall_parameter_22') && val.filter(v => v
				.key == 'mall_parameter_22').length ? val.filter(v => v.key == 'mall_parameter_22')[0].parameter : '';
		console.log(state.serviceTelInfo);
		//开启有图无图模式 mall_parameter_24
		state.noneImge = val && val.filter(v => v.key == 'mall_parameter_24') && val.filter(v => v
				.key == 'mall_parameter_24').length ? val.filter(v => v.key == 'mall_parameter_24')[0].parameter : '';
		//字段展示 商品简称
		state.commonityAbbreviation = val && val.filter(v => v.key == 'mall_parameter_15') && val.filter(v => v
				.key == 'mall_parameter_15').length ? val.filter(v => v.key == 'mall_parameter_15')[0].parameter : '';
		//字段展示 商品规格
		state.commonityNorms = val && val.filter(v => v.key == 'mall_parameter_16') && val.filter(v => v
				.key == 'mall_parameter_16').length ? val.filter(v => v.key == 'mall_parameter_16')[0].parameter : '';
		//字段展示 商品有效期
		state.commonityQualityGuaranteePeriod = val && val.filter(v => v.key == 'mall_parameter_20') && val.filter(v => v
				.key == 'mall_parameter_20').length ? val.filter(v => v.key == 'mall_parameter_20')[0].parameter : '';
		//字段展示 商品型号
		state.commonityModel = val && val.filter(v => v.key == 'mall_parameter_17') && val.filter(v => v
				.key == 'mall_parameter_17').length ? val.filter(v => v.key == 'mall_parameter_17')[0].parameter : '';
		//字段展示 商品产地
		state.commonityPlaceOfOrigin = val && val.filter(v => v.key == 'mall_parameter_18') && val.filter(v => v
				.key == 'mall_parameter_18').length ? val.filter(v => v.key == 'mall_parameter_18')[0].parameter : '';
		//字段展示 商品品牌
		state.commonityBrand = val && val.filter(v => v.key == 'mall_parameter_19') && val.filter(v => v
				.key == 'mall_parameter_19').length ? val.filter(v => v.key == 'mall_parameter_19')[0].parameter : '';
		//字段展示 商品自定义
		state.commonityZdy = val && val.filter(v => v.key == 'mall_parameter_31') && val.filter(v => v
				.key == 'mall_parameter_31').length ? val.filter(v => v.key == 'mall_parameter_31')[0].parameter : '';
		//商品分类 mall_parameter_23
		state.commonClassity = val && val.filter(v => v.key == 'mall_parameter_23') && val.filter(v => v
				.key == 'mall_parameter_23').length ? val.filter(v => v.key == 'mall_parameter_23')[0].parameter : '';
		//开启分仓模式 mall_parameter_25
		state.fencang = val && val.filter(v => v.key == 'mall_parameter_25') && val.filter(v => v
				.key == 'mall_parameter_25').length ? val.filter(v => v.key == 'mall_parameter_25')[0].parameter : '';
		//订单有效支付时长 mall_parameter_2
		state.payDate = val && val.filter(v => v.key == 'mall_parameter_2') && val.filter(v => v
				.key == 'mall_parameter_2').length ? val.filter(v => v.key == 'mall_parameter_2')[0].parameter : '';
		//退货寄回名称 mall_parameter_10
		state.returnOrderName = val && val.filter(v => v.key == 'mall_parameter_10') && val.filter(v => v
				.key == 'mall_parameter_10').length ? val.filter(v => v.key == 'mall_parameter_10')[0].parameter : '';
		//退货寄回手机号 mall_parameter_11
		state.returnOrderPhone = val && val.filter(v => v.key == 'mall_parameter_11') && val.filter(v => v
				.key == 'mall_parameter_11').length ? val.filter(v => v.key == 'mall_parameter_11')[0].parameter : '';
		//退货寄回省市区 mall_parameter_34
		state.returnOrderShengshiqu = val && val.filter(v => v.key == 'mall_parameter_34') && val.filter(v => v
				.key == 'mall_parameter_34').length ? val.filter(v => v.key == 'mall_parameter_34')[0].parameter : '';
		//退货寄回详细地址 mall_parameter_12
		state.returnOrderAddress = val && val.filter(v => v.key == 'mall_parameter_12') && val.filter(v => v
				.key == 'mall_parameter_12').length ? val.filter(v => v.key == 'mall_parameter_12')[0].parameter : '';
		//支付状态 mall_parameter_3
		state.payStatus = val && val.filter(v => v.key == 'mall_parameter_3') && val.filter(v => v
				.key == 'mall_parameter_3').length ? val.filter(v => v.key == 'mall_parameter_3')[0].parameter : '';
		// 促销订单仅支持在线支付 mall_parameter_4
		state.cuxiaoOrderPay = val && val.filter(v => v.key == 'mall_parameter_4') && val.filter(v => v
				.key == 'mall_parameter_4').length ? val.filter(v => v.key == 'mall_parameter_4')[0].parameter : '';
		//在线收款设置
		// 微信设置 mall_parameter_27
		state.weixinPay = val && val.filter(v => v.key == 'mall_parameter_27') && val.filter(v => v
				.key == 'mall_parameter_27').length ? val.filter(v => v.key == 'mall_parameter_27')[0].parameter : '';
		// 通联设置 mall_parameter_28
		state.tonglianPay = val && val.filter(v => v.key == 'mall_parameter_28') && val.filter(v => v
				.key == 'mall_parameter_28').length ? val.filter(v => v.key == 'mall_parameter_28')[0].parameter : '';
		// 富友设置 mall_parameter_29
		state.fuyouPay = val && val.filter(v => v.key == 'mall_parameter_29') && val.filter(v => v
				.key == 'mall_parameter_29').length ? val.filter(v => v.key == 'mall_parameter_29')[0].parameter : '';
		//线下支付 mall_parameter_30
		state.xianxiaPay = val && val.filter(v => v.key == 'mall_parameter_30') && val.filter(v => v
				.key == 'mall_parameter_30').length ? val.filter(v => v.key == 'mall_parameter_30')[0].parameter : '';
		
	}
}

//计算属性
const getters = {

}

//操作
const actions = {
	//获取系统设置
	async getSetting({commit}){
		// 参数类型[1：轮播图 2：功能主题 3：图文关联 4：品牌专区 5：活动专区 6：猜您喜欢 7：商城参数 8：微信支付 9：通联支付 10：富友支付 11：线下支付  12：首页配置]
		let data = await listMallParameter({type:7})
		console.log(data);
		commit('GLOBALSYSTEMSETTING',data.data.info)
		//获取小数位数
		let decimalData = await getMallBillParameterDecimals()
		console.log(decimalData);
		commit('GLOBALDECIMAL',decimalData.data.info)
	}
}

export default {
	namespaced: true,
	state,
	mutations,
	getters,
	actions
}
